using System;
using System.Linq;
using Engine;
using Game;

namespace RuthlessConquest {
    public class FactionSelectionDialog : ListSelectionDialog {
        public static Widget ItemWidgetFactory(object item) {
            Faction faction = (Faction)item;
            return new CanvasWidget {
                HorizontalAlignment = WidgetAlignment.Center,
                VerticalAlignment = WidgetAlignment.Center,
                Margin = new Vector2(0f, 0f),
                Children = {
                    new BevelledRectangleWidget {
                        Size = new Vector2(72f, 72f), CenterColor = Player.GetColor(faction), BevelColor = Player.GetColor(faction)
                    },
                    new RectangleWidget {
                        HorizontalAlignment = WidgetAlignment.Center,
                        VerticalAlignment = WidgetAlignment.Center,
                        Size = new Vector2(56f, 56f),
                        FillColor = Color.Black,
                        OutlineColor = Color.Transparent,
                        Subtexture = new Subtexture(Ship.GetTexture(faction), Vector2.Zero, Vector2.One)
                    }
                }
            };
        }

        public FactionSelectionDialog(Action<object> selectionHandler) : base(
            LanguageControl.Get("RCFactionSelectionDialog", "1"),
            Enumerable.Range(0, 6),
            96f,
            i => ItemWidgetFactory(i),
            selectionHandler
        ) {
            Direction = LayoutDirection.Horizontal;
            ContentSize = new Vector2(640f, 120f);
        }
    }
}